package com.useeinfo.oa.modules.base.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.CommonSugar;
import com.useeinfo.framework.sugar.tools.StringConverters;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 * @Auther: 陈炜
 * @Date: 2018/12/18 13:21
 * @Description: 设备批量导入
 */
@Entity
@Table(name = "facility_import")
public class FacilityImport extends SuperClassEntity<FacilityImport> {
    /**
     * 文件名
     */
    private String fileName;
    /**
     * 文件后缀
     */
    private String fileSuffix;
    /**
     * 文件全称（文件名+后缀）
     */
    private String fileWholeName;
    /**
     * 对应文件相对路径
     */
    private String filePath;
    /**
     * 文件大小
     */
    private String fileSize;
    /**
     * 状态（0未完成 1已完成）
     */
    private String status;
    /**
     * 总条数
     */
    private Integer totalCount;
    /**
     * 已完成条数
     */
    private Integer finishCount;
    /**
     * 异常条数
     */
    private Integer errorCount;
    /**
     * 异常信息
     */
    private String errorData;
    /**
     * 上传人ID
     */
    private Long systemUserId;
    /**
     * 上传人姓名
     */
    private String systemUserName;

    /**
     * 关联企业
     */
    @ManyToOne
    @JoinColumn(name = "enterprise_id")
    private Enterprise enterprise;

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getFileSuffix() {
        return fileSuffix;
    }

    public void setFileSuffix(String fileSuffix) {
        this.fileSuffix = fileSuffix;
    }

    public String getFileWholeName() {
        return fileWholeName;
    }

    public void setFileWholeName(String fileWholeName) {
        this.fileWholeName = fileWholeName;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public String getFileSize() {
        return fileSize;
    }

    public void setFileSize(String fileSize) {
        this.fileSize = fileSize;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getFinishCount() {
        return finishCount;
    }

    public void setFinishCount(Integer finishCount) {
        this.finishCount = finishCount;
    }

    public Integer getErrorCount() {
        return errorCount;
    }

    public void setErrorCount(Integer errorCount) {
        this.errorCount = errorCount;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    public Long getSystemUserId() {
        return systemUserId;
    }

    public void setSystemUserId(Long systemUserId) {
        this.systemUserId = systemUserId;
    }

    public String getSystemUserName() {
        return systemUserName;
    }

    public void setSystemUserName(String systemUserName) {
        this.systemUserName = systemUserName;
    }

    public String getErrorData() {
        return errorData;
    }

    public void setErrorData(String errorData) {
        this.errorData = errorData;
    }

    @Override
    public JSONObject toJSONObject() {
        JSONObject jsonObject = super.toJSONObject();
        jsonObject.put("fileName", StringConverters.null2String(getFileName()));
        jsonObject.put("fileSuffix", StringConverters.null2String(getFileSuffix()));
        jsonObject.put("fileWholeName", StringConverters.null2String(getFileWholeName()));
        jsonObject.put("filePath", StringConverters.null2String(getFilePath()));
        jsonObject.put("fileSize", StringConverters.null2String(getFileSize()));
        jsonObject.put("status", StringConverters.null2String(getStatus()));
        jsonObject.put("totalCount", CommonSugar.getTypedDefault(getTotalCount(), 0));
        jsonObject.put("finishCount", CommonSugar.getTypedDefault(getFinishCount(), 0));
        jsonObject.put("errorCount", CommonSugar.getTypedDefault(getErrorCount(), 0));
        jsonObject.put("systemUserId", CommonSugar.getTypedDefault(getSystemUserId(), 0L));
        jsonObject.put("systemUserName", StringConverters.null2String(getSystemUserName()));
        if(getEnterprise()!=null){
            jsonObject.put("enterpriseName", StringConverters.null2String(getEnterprise().getEnterpriseName()));
        }else{
            jsonObject.put("enterpriseName", "");
        }
        if(!"1".equals(getStatus())){
            jsonObject.put("statusText", "未完成");
        }else{
            jsonObject.put("statusText", "已完成");
        }
        return jsonObject;
    }
}
